package com.yjxxt.gradeList;


import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
/**
 * 视频单元考核(20.0%)	作业单元考核(50.0%)	考试单元考核(30.0%)	总成绩	性别
 * 20                       47.2	                30	         97.2	女
 */
public class StudentMapper  extends Mapper<LongWritable, Text, IntWritable, IntWritable> {
//public class StudentMapper  extends Mapper<LongWritable, Text, Text, IntWritable> {
    IntWritable one = new IntWritable(1);
   // Grade grade ;
    int i = 0;
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //对数据进行拆分
        String[] split = value.toString().split("\t");
        //判断数据是否为脏数据
        if (split != null && split.length == 5) {
            //开始进行数据的分拆
            double grade = Double.parseDouble(split[3])/10;
            /*double v_grade = Double.parseDouble(split[0]);
            double h_grade = Double.parseDouble(split[1]);
            double e_grade = Double.parseDouble(split[2]);
            double a_grade = Double.parseDouble(split[3]);
            String sex = split[4];*/
            //写出到Reduce
            context.write(new IntWritable((int)grade*10),one);//student
            /*grade = new Grade(i++, v_grade, h_grade, e_grade, a_grade, sex);
            context.write(new Text(grade.getId()+" "+grade.getV_grade()+" "+grade.getH_grade()+" "+
                    grade.getE_grade()+" "+grade.getA_grade()+" "+grade.getSex()), one);*/
        }
    }
}